import Vue from "vue";
import VueRouter from "vue-router"
import publicPlatform from "../../vue/views/publicPlatform";
import peopleList from "../../vue/views/publicPlatform/peopleList";
import questionAnalyse from "../../vue/views/publicPlatform/questionAnalyse";
import questionGroup from "../../vue/views/publicPlatform/questionGroup";
import shareList from "../../vue/views/publicPlatform/shareList";

Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    name: 'login',
    component: () => import('../views/login/index')
  },
  {
    path: '/getFace',
    name: 'getFace',
    component: () => import('../views/login/getFace')
  },
  {
    path: '/register',
    name: 'register',
    component: () => import('../views/login/register')
  },
  {
    path: '/Main',
    name: 'Main',
    component: () => import('../views/Main'),

    children: [
      {
        path: '/home',
        name: 'home',
        component: () => import('../views/home')
      },
      {
        path: '/publicPlatform',
        name:'publicPlatform',
        component: publicPlatform,
        children: [
          {
            path: 'peopleList',
            name: 'peopleList',
            component:peopleList
          },
          {
            path: 'questionAnalyse',
            name: 'questionAnalyse',
            component:questionAnalyse
          },
          {
            path: 'questionGroup',
            name: 'questionGroup',
            component:questionGroup
          },
          {
            path: 'shareList',
            name: 'shareList',
            component:shareList
          }
        ]
      },
      {
        path: '/testMessage',
        name: 'testMessage',
        component: () => import('../views/testMessage')
      },
      {
        path: '/publicPlatform/questionGroup',
        name: 'publicPlatform',
        component: () => import('../views/publicPlatform')
      },
      {
        path: '/peopleMessage',
        name: 'peopleMessage',
        component: () => import('../views/peopleMessage')
      },
      {
        path: '/testing',
        name: 'testing',
        component: () => import('../views/testing')
      }
    ]
  }
]

const router = new VueRouter({
  mode: "history",
  routes
})

router.beforeEach((to,from,next)=>{
  if(to.name==='register'||to.name==='login'||to.name!=='login'&&sessionStorage.getItem('token')){
    next();
  }else{
    next({name: 'login'});
  }
})

export default router
